package com.lizicloud.user.userupdate.converter;

import com.lizicloud.user.userupdate.dto.UserUpdateResponseDTO;
import com.lizicloud.domain.model.User;
import org.springframework.stereotype.Component;

/**
 * 用户更新转换器 - 实体与DTO之间的转换
 * 提供User实体与各种DTO之间的转换方法
 */
@Component
public class UserUpdateConverter {
    
    /**
     * User实体转换为UserUpdateResponseDTO
     * 
     * @param user 用户实体
     * @return 用户更新响应DTO
     */
    public UserUpdateResponseDTO toResponseDTO(User user) {
        if (user == null) {
            return null;
        }
        
        UserUpdateResponseDTO responseDTO = new UserUpdateResponseDTO();
        responseDTO.setId(user.getId());
        responseDTO.setUseraccount(user.getUseraccount());
        responseDTO.setUsername(user.getUsername());
        responseDTO.setEmail(user.getEmail());
        responseDTO.setPhone(user.getPhone());
        responseDTO.setRole(user.getRole());
        responseDTO.setStatus(user.getStatus());
        responseDTO.setAvatar(user.getAvatar());
        responseDTO.setRemark(user.getRemark());
        responseDTO.setCreatedTime(user.getCreatedTime());
        responseDTO.setUpdatedTime(user.getUpdatedTime());
        
        return responseDTO;
    }
    
    /**
     * UserUpdateResponseDTO转换为User实体
     * 注意：这个方法不会转换所有字段，主要用于部分字段的转换
     * 
     * @param responseDTO 用户更新响应DTO
     * @return 用户实体
     */
    public User toEntity(UserUpdateResponseDTO responseDTO) {
        if (responseDTO == null) {
            return null;
        }
        
        User user = new User();
        user.setId(responseDTO.getId());
        user.setUseraccount(responseDTO.getUseraccount());
        user.setUsername(responseDTO.getUsername());
        user.setEmail(responseDTO.getEmail());
        user.setPhone(responseDTO.getPhone());
        user.setRole(responseDTO.getRole());
        user.setStatus(responseDTO.getStatus());
        user.setAvatar(responseDTO.getAvatar());
        user.setRemark(responseDTO.getRemark());
        user.setCreatedTime(responseDTO.getCreatedTime());
        user.setUpdatedTime(responseDTO.getUpdatedTime());
        
        return user;
    }
}